home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freaks Macintosh Archive
/
Freaks Macintosh Archive.bin
/
Freaks Macintosh Archives
/
Macintosh
/
Development & Resource Tools
/
ROM Sucker.sit
/
ROM Sucker
/
src
/
ROM_Sucker.s
next >
Wrap
Text File
|
1998-01-04
|
43KB
|
1,719 lines
******************************
* ROM Sucker
* Adapted from 680x0 to PPC assembly language
* Started: November 24, 1997
* Modified: January 3, 1998
*
* Resizing window when scrolled causes havoc with control values, etc.
* So live with it. This is just a hack, after all.
*
bss: reg r30 ;global data register
Start:
ENTRY
start_up ;save r0, r10 - r31 and set up r30 for globals
la r3,qd(`bss) ;I-2-36: QuickDraw global variables
addic r3,r3,208-4
Xcall InitGraf ;I-2-36
Xcall InitFonts ;T-4-51
Xcall InitWindows ;TE-4-75
Xcall InitMenus ;TE-3-103
Xcall TEInit ;T-2-77
li r3,0
Xcall InitDialogs ;TE-6-103
Xcall InitCursor ;I-8-22
SetupStuff:
li r3,TRUE
sth r3,NormalScroll(`bss) ;set up scroll behavior
li r3,FALSE
sth r3,DARefNum(`bss) ;use as a flag that a DA is open
Xcall GetCaretTime ;TE-2-113 (yeah, I know it’s in a global variable)
sth r3,MyCaretTime(`bss) ;caret blinking interval in ticks
lis r3,"ac" ;load and shift into upper half
ori r3,r3,"ur" ;fill in the lower half
li r4,0 ;resource ID number
Xcall GetResource ;MT-1-73
stw r3,acurHandle(`bss)
lwz r13,(r3) ;acur handle --> acur record
lhz r14,(r13) ;get the number of cursors
subi r14,r14,1 ;we’ll index backwards thru the list
addi r13,r13,4 ;point at the cursor ID list
la r17,CursorHandles(`bss) ;ptr to the array of cursor handles
SS1: slwi r16,r14,2 ;multiply it by 4
lhzx r3,r13,r16 ;cursor ID number
Xcall GetCursor ;I-8-24
stwx r3,r17,r16 ;store the handle in the array
subic. r14,r14,1 ;decrement number of cursors index
bge SS1 ;we COULD get these guys on the fly, but…
WindowSetup:
li r3,128 ;window ID is 128
li r4,0 ;use heap for record
li r5,-1 ;make it the front window
Xcall GetNewCWindow ;TE-4-76
stw r3,WindowPtr(`bss)
Xcall SetPort ;I-2-42: WindowPtr in r3
li r3,128 ;control ID
lwz r4,WindowPtr(`bss) ;window ptr (control owner)
Xcall GetNewControl ;TE-5-81
stw r3,VScrollHandle(`bss)
TextSetup:
li r3,monaco ;T-4-15: font family ID
Xcall TextFont ;T-3-69
li r3,9 ;font size: 9 point
Xcall TextSize ;T-3-73
li r3,0 ;text face: 0 = plain style
Xcall TextFace ;T-3-69
li r3,srcOr ;text mode
Xcall TextMode ;T-3-70
la r3,FontInfo(`bss) ;VAR: FontInfo record: T-3-66
Xcall GetFontInfo ;T-3-75
lwz r3,WindowPtr(`bss)
la r3,portRect(r3) ;dest rect = portRect
mr r4,r3 ;view rect = portRect
Xcall TENew ;T-2-78
stw r3,TEHandle(`bss)
bl SizeDest ;we’ll do these again after the window is sized
bl SizeView
lwz r3,TEHandle(`bss)
lwz r3,(r3) ;TEHandle --> ptr to edit record
la r4,FontInfo(`bss) ;ptr to FontInfo data record
lhz r5,(r4) ;ascent
sth r5,fontAscent(r3) ;fontAscent
lhz r6,descent(r4)
add r5,r5,r6 ;+ descent
lhz r6,leading(r4)
add r5,r5,r6 ;+ leading
sth r5,lineHeight(r3) ; = line height
li r4,monaco
sth r4,teFont(r3) ;teFont = Monaco
li r4,9
sth r4,teSize(r3) ;teSize = 9 point
MakeMenu:
li r3,128 ;MBAR resource ID
Xcall GetNewMBar ;TE-3-111
stw r3,MBARHandle(`bss)
Xcall SetMenuBar ;TE-3-112
li r3,128 ;menu ID for Apple menu
Xcall GetMenuHandle ;TE-3-122
stw r3,AppleMenuHandle(`bss) ;needed for DAs (remember them?)
lwz r3,AppleMenuHandle(`bss)
lis r4,"DR" ;load and shift into upper half
ori r4,r4,"VR" ;fill in the low half
Xcall AppendResMenu ;TE-3-128
li r3,130 ;menu ID for Edit menu
Xcall GetMenuHandle ;TE-3-122
stw r3,EditMenuHandle(`bss)
lwz r3,EditMenuHandle(`bss)
li r4,0 ;item number: 0 = whole menu
Xcall DisableItem ;TE-3-131
li r3,131 ;menu ID for Options menu
Xcall GetMenuHandle ;TE-3-122
stw r3,OptionMenuHandle(`bss)
Xcall DrawMenuBar ;TE-3-113
AlmostReady:
bl CenterWindow ;center the window on the screen
bl AdjustWindowSize ;size the window to fit the screen
bl SizeDest ;adjust dest rect to window size
bl SizeView ;adjust view rect to window size
bl SizeScrollBar ;fit scroll bar in window
lwz r3,WindowPtr(`bss)
Xcall ShowWindow ;TE-4-88: make the window visible
bl GetTheResources ;read in the ROM resources
bl CalControl ;calibrate the scroll bar to the text
bl SaveTheResources ;put the resources in a ResEdit file
li r3,everyEvent ;TE-2-26: whichMask: -1 = everyEvent
li r4,0 ;TE-2-26: stopMask: 0 = all events
Xcall FlushEvents ;TE-2-93
EventLoop:
li r3,everyEvent ;TE-2-85: eventMask: -1 = everyEvent
la r4,theEvent(`bss) ;VAR: TE-2-79: EventRecord
lhz r5,MyCaretTime(`bss) ;sleep time in ticks
li r6,0 ;mouseRgn
Xcall WaitNextEvent ;TE-2-85
lhz r3,What+theEvent(`bss) ;TE-2-79: event code
cmpwi r3,1 ;MouseDown
beq MouseDown
cmpwi r3,3 ;KeyDown
beq KeyDown
cmpwi r3,5 ;AutoKey
beq KeyDown
cmpwi r3,6 ;Update
beq UpdateEvent
cmpwi r3,8 ;Activate
beq ActivateEvent
cmpwi r3,15 ;OSEvent
beq OSEvent
cmpwi r3,23 ;high-level event
beq HighLevelEvent
b EventLoop ;none of the above
MouseDown:
lwz r3,thePt+theEvent(`bss) ;point where mouse was clicked from WaitNextEvent
la r4,whichWindow(`bss) ;VAR: window in which mousedown occurred
Xcall FindWindow ;TE-4-91
sth r3,partCode(`bss) ;TE-4-92: (for ZoomWindow)
cmpwi r3,8 ;highest code we know about
bgt EventLoop
la r4,[t]InDeskx(rtoc) ;our MouseDown jump table
slwi r3,r3,2 ;x4 to index into the table
lwzx r4,r3,r4 ;get the address of the routine
mtctr r4 ;put the address in the CTR register
bctr ;branch to CTR
b EventLoop ;shouldn’t get here
* 0: click in desk InDeskx
* 1: in menu bar DoMenu
* 2: in DA’s window InSysWindowx
* 3: select a window InContentx
* 4: in title bar DoDrag
* 5: in grow box DoGrow
* 6: in close box DoGoAway
* 7: in zoom box DoZoomIn
* 8: in zoom box DoZoomOut
InDeskx: toc_routine
b EventLoop ;we ignore clicks in the desktop
DoMenu: toc_routine
lwz r3,thePt+theEvent(`bss)
Xcall MenuSelect ;TE-3-115: returns r3 = menusID:ItemID
stw r3,MenuResult(`bss)
Menu2: srwi r3,r3,16 ;we want to look at the menu ID number
cmpwi r3,128 ;is it Apple?
beq AppleMenu
cmpwi r3,129 ;is it File?
beq FileMenu
cmpwi r3,130 ;is it Edit?
beq EditMenu
cmpwi r3,131 ;is it Options?
beq OptionsMenu
MenuExit:
li r3,0 ;0 = kill hiliting
Xcall HiliteMenu ;TE-3-119
b EventLoop
AppleMenu:
lhz r3,itemID+MenuResult(`bss) ;get itemID
cmpwi r3,1 ;is it About?
beq DoAbout
la r3,OldPort(`bss)
Xcall GetPort ;I-2-41
lwz r3,AppleMenuHandle(`bss)
lhz r4,itemID+MenuResult(`bss) ;get itemID
la r5,itemString(`bss) ;VAR: name of DA
Xcall GetMenuItemText ;TE-3-132
lwz r3,EditMenuHandle(`bss)
li r4,0 ;item number: 0 = whole menu
Xcall EnableItem ;TE-3-131
la r3,itemString(`bss) ;name of DA
Xcall OpenDeskAcc ;D-1-65
sth r3,DARefNum(`bss) ;save DA refNum
la r3,OldPort(`bss) ;restore the port
Xcall SetPort ;I-2-42
lwz r3,EditMenuHandle(`bss)
li r4,0 ;item number: 0 = whole menu
Xcall DisableItem ;TE-3-131
Xcall DrawMenuBar ;TE-3-113
b MenuExit
DoAbout:
la r3,OldPort(`bss)
Xcall GetPort ;I-2-41
li r3,geneva ;T-4-15: font family ID
Xcall SetDialogFont ;TE-6-105
li r3,128 ;Dialog #128 is About
li r4,0 ;use heap for DStorage
li r5,-1 ;in front
Xcall GetNewDialog ;TE-6-113
stw r3,DialogPtr(`bss)
Xcall SetPort ;I-2-42
li r3,9 ;font size: 9 point
Xcall TextSize ;T-3-73
lwz r3,AboutText(rtoc) ;ptr to the text
lwz r4,AboutTextEnd(rtoc)
lwz r5,AboutText(rtoc)
sub r4,r4,r5 ;get the length of the text
lwz r5,DialogPtr(`bss)
la r5,portRect(r5)
la r6,textRect(`bss) ;rect to display the text in (local coordinates)
lis r8,3
ori r8,r8,3 ;now it’s $00030003
stw r8,topLeft(r6) ;+3 for top, +3 for left
lwz r7,bottomRight(r5)
sub r7,r7,r8 ;-3 for bottom, -3 for right
stw r7,bottomRight(r6)
li r6,teCenter ;T-2-89: type of text alignment
Xcall TETextBox ;T-2-88
DA1: li r3,$002E ;TE-2-85: EventMask: mouse & keyboard events
la r4,theEvent(`bss) ;TE-2-79: EventRecord
lhz r5,MyCaretTime(`bss) ;sleep time in ticks
li r6,0 ;mouseRgn
Xcall WaitNextEvent ;TE-2-85
cmpwi r3,FALSE ;TRUE means we got a mouse or keyboard event
beq DA1
lwz r3,DialogPtr(`bss) ;got a hit: dump the dialog
Xcall DisposeDialog ;TE-6-120
lwz r3,OldPort(`bss) ;back to the old port
Xcall SetPort ;I-2-42
li r3,systemFont ;T-4-15: font family ID
Xcall SetDialogFont ;TE-6-105
b MenuExit
FileMenu:
b Quit ;nothing else implemented
EditMenu:
lhz r3,itemID+MenuResult(`bss) ;get itemID
subi r3,r3,1 ;offset for SystemEdit
Xcall SystemEdit ;TE-3-122
cmpwi r3,FALSE ;TRUE if DA handled command
bne MenuExit
lhz r3,itemID+MenuResult(`bss) ;get itemID
cmpwi r3,1 ;is it Undo?
beq MenuExit ;sorry, no Undo-ing
cmpwi r3,3 ;Cut?
bne EM1
lwz r3,TEHandle(`bss)
Xcall TECut ;T-2-94
b MenuExit
EM1: cmpwi r3,4 ;Copy?
bne EM2
lwz r3,TEHandle(`bss)
Xcall TECopy ;T-2-95
b MenuExit
EM2: cmpwi r3,5 ;Paste?
bne EM3
lwz r3,TEHandle(`bss)
Xcall TEPaste ;T-2-95
b MenuExit
EM3: cmpwi r3,6 ;Clear?
bne MenuExit
lwz r3,TEHandle(`bss)
Xcall TEDelete ;T-2-93
b MenuExit
OptionsMenu:
lhz r3,itemID+MenuResult(`bss) ;get itemID
cmpwi r3,1 ;is it normal scroll?
bne SM1
lwz r3,OptionMenuHandle(`bss)
li r4,1 ;item number 1 = Normal scroll
li r5,TRUE ;TRUE = check, FALSE = remove check
Xcall CheckItem ;TE-3-136
lwz r3,OptionMenuHandle(`bss)
li r4,2 ;item number 2 = Smooth scroll
li r5,FALSE ;TRUE = check, FALSE = remove check
Xcall CheckItem ;TE-3-136
li r3,TRUE
sth r3,NormalScroll(`bss)
b MenuExit
SM1 lwz r3,OptionMenuHandle(`bss)
li r4,1 ;item number 1 = Normal scroll
li r5,FALSE ;TRUE = check, FALSE = remove check
Xcall CheckItem ;TE-3-136
lwz r3,OptionMenuHandle(`bss)
li r4,2 ;item number 2 = Smooth scroll
li r5,TRUE ;TRUE = check, FALSE = remove check
Xcall CheckItem ;TE-3-136
li r3,FALSE
sth r3,NormalScroll(`bss)
b MenuExit
InSysWindowx: toc_routine
la r3,theEvent(`bss) ;from WaitNextEvent
la r4,whichWindow(`bss) ;from FindWindow
Xcall SystemClick ;TE-2-94
b EventLoop
InContentx: toc_routine
lwz r3,WindowPtr(`bss)
Xcall SetPort ;I-2-42
la r3,MousePt(`bss) ;I-2-27: local coordinates
Xcall GetMouse ;TE-2-108
lwz r3,MousePt(`bss) ;local mouse coordinates
lwz r4,whichWindow(`bss) ;window ptr
la r5,CtrlHandle(`bss) ;VAR: handle to control
Xcall FindControl ;TE-5-89: returns partCode
cmpwi r3,0 ;0 = in content area, otherwise in a control
beq EventLoop
InAControl:
cmpwi r3,inUpButton ;20 = $14
beq DoUpButton
cmpwi r3,inDownButton ;21 = $15
beq DoDownButton
cmpwi r3,inPageUp ;22 = $16
beq DoPageUp
cmpwi r3,inPageDown ;23 = $17
beq DoPageDown
cmpwi r3,inThumb ;129 = $81
beq DoInThumb
b EventLoop ;shouldn’t ever get here
DoUpButton:
lwz r3,VScrollHandle(`bss)
li r4,inUpButton
Xcall HiliteControl ;TE-5-98
lwz r13,TEHandle(`bss) ;TERec handle
lwz r13,(r13) ;TERec handle --> TERec ptr
lhz r13,lineHeight(r13) ;save the lineHeight
lhz r14,NormalScroll(`bss) ;for checking scrolling behavior
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
mr r15,r3 ;hang on to this one, too
DUB1: cmpwi r15,0 ;compare to minimum value = 0
beq DUB6 ;branch if at minimum
lwz r3,VScrollHandle(`bss)
subi r15,r15,1 ;decrement control value
mr r4,r15
Xcall SetControlValue ;TE-5-94
cmpwi r14,FALSE ;what kind of scrolling are we doing?
bne DUB4
mr r16,r13 ;lineHeight = amount to scroll
DUB3: li r3,0 ;dh
li r4,1 ;dv: scroll one pixel line at a time
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
subic. r16,r16,1
bne DUB3 ;go back around until we’ve scrolled one line’s worth
b DUB6
DUB4: li r3,0 ;dh
mr r4,r13 ;dv = lineHeight = amount to scroll
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
DUB6: Xcall Button ;TE-2-108
cmpwi r3,FALSE ;returns boolean button state: TRUE = button down
beq DUBx ;exit if button is up
la r3,MousePt(`bss) ;VAR: local coordinates
Xcall GetMouse ;TE-2-108
lwz r3,VScrollHandle(`bss)
lwz r4,MousePt(`bss)
Xcall TestControl ;TE-5-93: returns partCode in r3
cmpwi r3,inUpButton ;20 = $14
beq DUB1 ;scroll some more if we’re still in the up button
b DUB6 ;keep looping as long as the button is down
DUBx: lwz r3,VScrollHandle(`bss)
li r4,0 ;normal hiliting
Xcall HiliteControl ;TE-5-98
b EventLoop
DoDownButton:
lwz r3,VScrollHandle(`bss)
li r4,inDownButton
Xcall HiliteControl ;TE-5-98
lwz r13,TEHandle(`bss) ;TERec handle
lwz r13,(r13) ;TERec handle --> TERec ptr
lhz r13,lineHeight(r13) ;save the lineHeight
lwz r3,VScrollHandle(`bss)
Xcall GetControlMaximum ;TE-5-104
mr r14,r3 ;put it where it will stick around
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
mr r15,r3 ;hang on to this one, too
lhz r17,NormalScroll(`bss) ;for checking scrolling behavior
DDB1: cmpw r15,r14 ;compare to maximum value
bge DDB6 ;branch if too big
lwz r3,VScrollHandle(`bss)
addi r15,r15,1 ;increment control value
mr r4,r15
Xcall SetControlValue ;TE-5-94
cmpwi r17,FALSE ;type of scrolling
bne DDB4
mr r16,r13 ;lineHeight = amount to scroll
DDB3: li r3,0 ;dh
li r4,-1 ;dv: scroll one pixel line at a time
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
subic. r16,r16,1
bne DDB3 ;go back around until we’ve scrolled one line’s worth
b DDB6
DDB4: li r3,0 ;dh
mr r4,r13 ;lineHeight = amount to scroll
neg r4,r4 ;negative to go up
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
DDB6: Xcall Button ;TE-2-108
cmpwi r3,FALSE ;returns boolean button state: TRUE = button down
beq DDBx ;exit if button is up
la r3,MousePt(`bss) ;VAR: local coordinates
Xcall GetMouse ;TE-2-108
lwz r3,VScrollHandle(`bss)
lwz r4,MousePt(`bss)
Xcall TestControl ;TE-5-93: returns partCode in r3
cmpwi r3,inDownButton ;21 = $15
beq DDB1 ;scroll some more if we’re still in the down button
b DDB6 ;stay here while the button is down
DDBx: lwz r3,VScrollHandle(`bss)
li r4,0 ;normal hiliting
Xcall HiliteControl ;TE-5-98
b EventLoop
DoPageUp:
lwz r3,TEHandle(`bss) ;TERec handle
lwz r3,(r3) ;TERec handle --> TERec ptr
la r4,viewRect(r3)
lhz r5,top(r4)
lhz r6,bottom(r4)
sub r6,r6,r5 ;get height of window
lhz r14,lineHeight(r3) ;the height of one line
divwu r13,r6,r14 ;how many lines fit in the window
subi r13,r13,1 ;to see one of the old lines
DPU1: lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpwi r3,0 ;check it
beq DPU6 ;don’t go lower than zero
sub. r4,r3,r13 ;control value - (# lines - 1)
mr r15,r13
bge DPU2 ;must be positive
mr r15,r3 ;for TEScroll
li r4,0 ;zero is minimum value
DPU2: lwz r3,VScrollHandle(`bss)
Xcall SetControlValue ;TE-5-94
li r3,0 ;dh
mullw r4,r14,r15 ;dv = lineHeight x (# of lines/window -1)
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
li r3,6 ;6/60 = 1/10 second
la r4,finalTicks(`bss) ;VAR: value of Ticks at end of delay
Xcall Delay ;II-284 (doesn’t seem to be in new Inside Macintosh)
DPU6: Xcall Button ;TE-2-108
cmpwi r3,FALSE ;returns boolean button state: TRUE = button down
beq DPUx ;exit if button is up
la r3,MousePt(`bss) ;VAR: local coordinates
Xcall GetMouse ;TE-2-108
lwz r3,VScrollHandle(`bss)
lwz r4,MousePt(`bss)
Xcall TestControl ;TE-5-93: returns partCode in r3
cmpwi r3,inPageUp ;22 = $16
beq DPU1 ;keep scrolling if we’re still in the page up area
DPUx: b EventLoop
DoPageDown:
lwz r3,TEHandle(`bss) ;TERec handle
lwz r3,(r3) ;TERec handle --> TERec ptr
la r4,viewRect(r3)
lhz r5,top(r4)
lhz r6,bottom(r4)
sub r6,r6,r5 ;get height of window
lhz r14,lineHeight(r3) ;the height of one line
divwu r13,r6,r14 ;how many lines fit in the window
subi r13,r13,1 ;to see one of the old lines
lwz r3,VScrollHandle(`bss)
Xcall GetControlMaximum ;TE-5-104
mr r15,r3 ;put it where it will stick around
DPD1: lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpw r3,r15 ;check against maximum value
bge DPD6 ;branch if too big
add r4,r3,r13 ;control value + (# lines - 1)
mr r16,r13 ;for TEScroll
cmpw r4,r15 ;compare to max value
ble DPD2 ;OK if <= max
sub r16,r15,r3 ;difference between present & max is amount to scroll
mr r4,r15 ;go to max value
DPD2: lwz r3,VScrollHandle(`bss)
Xcall SetControlValue ;TE-5-94
li r3,0 ;dh
mullw r4,r14,r16 ;dv = lineHeight x (# of lines to scroll)
neg r4,r4 ;negative to go up
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
li r3,6 ;6/60 = 1/10 second
la r4,finalTicks(`bss) ;VAR: value of Ticks at end of delay
Xcall Delay ;II-284
DPD6: Xcall Button ;TE-2-108
cmpwi r3,FALSE ;returns boolean button state: TRUE = button down
beq DPDx ;exit if button is up
la r3,MousePt(`bss) ;VAR: local coordinates
Xcall GetMouse ;TE-2-108
lwz r3,VScrollHandle(`bss)
lwz r4,MousePt(`bss)
Xcall TestControl ;TE-5-93: returns partCode in r3
cmpwi r3,inPageDown ;23 = $17
beq DPD1 ;keep scrolling if in the page down area
DPDx: b EventLoop
DoInThumb:
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
mr r13,r3 ;save it for later…
lwz r3,VScrollHandle(`bss)
lwz r4,MousePt(`bss) ;we got it ’way back
li r5,0 ;no actionProc
Xcall TrackControl ;TE-5-90
lwz r3,VScrollHandle(`bss)
lwz r3,(r3) ;ptr to ControlRecord
lhz r4,contrlValue(r3) ;new control value
sub. r4,r4,r13 ;get difference between new and old value
beq DITx ;don’t scroll if it didn’t change
lwz r3,TEHandle(`bss)
lwz r3,(r3) ;TERec ptr
lhz r3,lineHeight(r3)
mullw r4,r3,r4 ;dv = (lineHeight) x (# of lines)
neg r4,r4
li r3,0 ;dh
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
DITx: b EventLoop
DoDrag: toc_routine
Xcall GetGrayRgn ;TE-4-113: returns handle to desktop region
lwz r3,(r3) ;handle --> ptr
la r3,rgnBBox(r3) ;now have desktop rect
la r4,boundsRect(`bss) ;boundsRect for DragWindow
lwz r5,topLeft(r3) ;get topLeft…
stw r5,topLeft(r4)
lwz r5,bottomRight(r3) ;…and bottomRight
stw r5,bottomRight(r4)
lwz r3,WindowPtr(`bss)
lwz r4,thePt+theEvent(`bss) ;where (global)
la r5,boundsRect(`bss)
Xcall DragWindow ;TE-4-94
b EventLoop
DoGrow: toc_routine
lwz r3,whichWindow(`bss) ;window ptr
la r3,portRect(r3)
Xcall InvalRect ;TE-4-107
Xcall GetGrayRgn ;TE-4-113: returns handle to desktop region
lwz r3,(r3) ;handle --> ptr
la r3,rgnBBox(r3) ;now have desktop rect
la r4,sizeRect(`bss) ;sizeRect for GrowWindow
lwz r5,topLeft(r3) ;get topLeft…
stw r5,topLeft(r4)
lwz r5,bottomRight(r3) ;…and bottomRight
stw r5,bottomRight(r4)
lwz r3,WindowPtr(`bss)
lwz r4,thePt+theEvent(`bss) ;global coordinates of mousedown
la r5,sizeRect(`bss) ;maximum size limits
Xcall GrowWindow ;TE-4-100: returns r3 = height:width
mr r4,r3 ;new height
mr r5,r3
srwi r5,r5,16 ;new width
lwz r3,WindowPtr(`bss)
li r6,TRUE ;fUpdate? (new area --> update region)
Xcall SizeWindow ;TE-4-101
bl SizeScrollBar ;fit controls to new window size
bl SizeDest
bl SizeView ;adjust to window size
bl CalControl ;calibrate scroll bar to new size
lwz r3,TEHandle(`bss)
Xcall TECalText ;T-2-89
b EventLoop
DoGoAway: toc_routine
lwz r3,whichWindow(`bss) ;window ptr
lwz r4,thePt+theEvent(`bss) ;from WaitNextEvent
Xcall TrackGoAway ;TE-4-103: returns boolean: in/out of GoAway box on mouseup
cmpwi r3,FALSE ;TRUE = in GoAway box
bne Quit
b EventLoop
DoZoomIn: toc_routine
DoZoomOut: toc_routine
lwz r3,WindowPtr(`bss)
lwz r4,thePt+theEvent(`bss) ;where (global)
lhz r5,partCode(`bss) ;from FindWindow
Xcall TrackBox ;TE-4-101
cmpwi r3,FALSE ;see if it’s still in the zoom box
beq DZx
lwz r3,WindowPtr(`bss)
lhz r4,partCode(`bss)
li r5,TRUE ;bring to front?
Xcall ZoomWindow ;TE-4-102
lwz r3,WindowPtr(`bss)
lwz r3,portRect(r3)
Xcall InvalRect ;TE-4-107
bl SizeScrollBar ;fit control to new window size
bl SizeView ;adjust to window size
bl CalControl ;calibrate scroll bar to new size
lwz r3,TEHandle(`bss)
Xcall TECalText ;T-2-89
DZx: b EventLoop
KeyDown:
lhz r4,Modify+theEvent(`bss) ;TE-2-20: modifier flags
andi. r4,r4,$0100 ;see if cmd key is down
beq KD1 ;branch if not
lbz r3,Message+3+theEvent(`bss) ;TE-2-40: the character code
Xcall MenuKey ;TE-3-117
stw r3,MenuResult(`bss) ;save the result
cmpwi r3,0 ;see if it’s one of our menu items
beq EventLoop ;outta here if no match
b Menu2 ;handle it
KD1: lbz r3,Message+3+theEvent(`bss) ;get the character code
cmpwi r3,$1F ;check for control chars
ble ControlChar ;go check for up/dn arrow, home, end, pg up/dn
b EventLoop
ControlChar: ;T-1-55: character codes
cmpwi r3,$1E ;$1E = up arrow
beq UpArrow
cmpwi r3,$1F ;$1F = down arrow
beq DownArrow
cmpwi r3,$0B ;$0B = page up
beq PageUp
cmpwi r3,$0C ;$0C = page down
beq PageDown
cmpwi r3,$01 ;$01 = home
beq Home
cmpwi r3,$04 ;$04 = end
beq ScrollToEnd
; cmpwi r3,$05 ;$05 = help
; beq Help ;no help here (at least, not yet)
b EventLoop
UpArrow:
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpwi r3,0 ;compare to minimum value = 0
beq UAx ;exit if at minimum
mr r4,r3
subi r4,r4,1 ;decrement control value
lwz r3,VScrollHandle(`bss)
Xcall SetControlValue ;TE-5-94
li r3,0 ;dh
lwz r5,TEHandle(`bss) ;TERec handle
lwz r4,(r5) ;TERec handle --> TERec ptr
lhz r4,lineHeight(r4) ;dv = lineHeight = amount to scroll
Xcall TEScroll ;T-2-91
UAx: b EventLoop
DownArrow:
lwz r3,VScrollHandle(`bss)
Xcall GetControlMaximum ;TE-5-104
mr r13,r3 ;put it where it will stick around
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpw r3,r13 ;compare to maximum value
bge DAx ;exit if too big
mr r4,r3
addi r4,r4,1 ;increment control value
lwz r3,VScrollHandle(`bss)
Xcall SetControlValue ;TE-5-94
li r3,0 ;dh
lwz r5,TEHandle(`bss) ;TERec handle
lwz r4,(r5) ;TERec handle --> TERec ptr
lhz r4,lineHeight(r4) ;dv = lineHeight = amount to scroll
neg r4,r4 ;negative to go up
Xcall TEScroll ;T-2-91
DAx: b EventLoop
PageUp:
lwz r3,TEHandle(`bss) ;TERec handle
lwz r3,(r3) ;TERec handle --> TERec ptr
la r4,viewRect(r3)
lhz r5,top(r4)
lhz r6,bottom(r4)
sub r6,r6,r5 ;get height of window
lhz r14,lineHeight(r3) ;the height of one line
divwu r13,r6,r14 ;how many lines fit in the window
subi r13,r13,1 ;to see one of the old lines
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpwi r3,0 ;check it
beq PUx ;don’t go lower than zero
sub. r4,r3,r13 ;control value - (# lines - 1)
bge DPU1 ;must be positive
mr r13,r3 ;for TEScroll
li r4,0 ;zero is minimum value
PU1: lwz r3,VScrollHandle(`bss)
Xcall SetControlValue ;TE-5-94
li r3,0 ;dh
mullw r4,r14,r13 ;dv = lineHeight x (# of lines/window - 1)
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
PUx: b EventLoop
PageDown:
lwz r3,TEHandle(`bss) ;TERec handle
lwz r3,(r3) ;TERec handle --> TERec ptr
la r4,viewRect(r3)
lhz r5,top(r4)
lhz r6,bottom(r4)
sub r6,r6,r5 ;get height of window
lhz r14,lineHeight(r3) ;the height of one line
divwu r13,r6,r14 ;how many lines fit in the window
subi r13,r13,1 ;to see one of the old lines
lwz r3,VScrollHandle(`bss)
Xcall GetControlMaximum ;TE-5-104
mr r15,r3 ;put it where it will stick around
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpw r3,r15 ;check against maximum value
bge PDx ;exit if too big
add r4,r3,r13 ;control value + (# lines - 1)
mr r16,r13 ;for TEScroll
cmpw r4,r15 ;compare to max value
ble PD1 ;OK if <= max
sub r16,r15,r3 ;difference between present & max is amount to scroll
mr r4,r15 ;go to max value
PD1: lwz r3,VScrollHandle(`bss)
Xcall SetControlValue ;TE-5-94
li r3,0 ;dh
mullw r4,r14,r16 ;dv = lineHeight x (# of lines to scroll)
neg r4,r4 ;negative to go up
lwz r5,TEHandle(`bss)
Xcall TEScroll ;T-2-91
PDx: b EventLoop
Home:
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
cmpwi r3,0 ;compare to minimum value = 0
beq Hx ;no scroll if already zero
mr r13,r3 ;save it
li r3,0 ;dh
lwz r5,TEHandle(`bss) ;TERec handle
lwz r4,(r5) ;TERec handle --> TERec ptr
lhz r4,lineHeight(r4)
mullw r4,r4,r13 ;dv = lineHeight * control value = amount to scroll
Xcall TEScroll ;T-2-91
lwz r3,VScrollHandle(`bss)
li r4,0 ;new control value
Xcall SetControlValue ;TE-5-94
Hx: b EventLoop
ScrollToEnd:
lwz r3,VScrollHandle(`bss)
Xcall GetControlMaximum ;TE-5-104
mr r13,r3 ;put it where it will stick around
lwz r3,VScrollHandle(`bss)
Xcall GetControlValue ;TE-5-103
sub. r6,r13,r3 ;for TEScroll
beq STEx ;don’t scroll if we’re already there
li r3,0 ;dh
lwz r5,TEHandle(`bss) ;TERec handle
lwz r4,(r5) ;TERec handle --> TERec ptr
lhz r4,lineHeight(r4)
mullw r4,r4,r6 ;dv = lineHeight * control value = amount to scroll
neg r4,r4
Xcall TEScroll ;T-2-91
lwz r3,VScrollHandle(`bss)
mr r4,r13 ;new control value = maximum
Xcall SetControlValue ;TE-5-94
STEx: b EventLoop
UpdateEvent:
lwz r3,Message+theEvent(`bss) ;window ptr
lwz r4,WindowPtr(`bss)
cmpw r3,r4
bne UEx ;not for us
lwz r3,Message+theEvent(`bss)
Xcall BeginUpdate ;TE-4-106
bl DrawWindow
lwz r3,WindowPtr(`bss)
la r3,portRect(r3)
lwz r4,TEHandle(`bss)
Xcall TEUpdate ;T-2-88
lwz r3,VScrollHandle(`bss)
Xcall Draw1Control ;TE-5-88
lwz r3,Message+theEvent(`bss)
Xcall EndUpdate ;TE-4-107
UEx: b EventLoop
DrawWindow:
mflr r28
lwz r3,WindowPtr(`bss)
Xcall SetPort ;I-2-42
lwz r3,WindowPtr(`bss)
la r3,portRect(r3)
Xcall EraseRect ;I-3-61
lwz r3,WindowPtr(`bss)
Xcall DrawGrowIcon ;TE-4-86
mtlr r28
blr
ActivateEvent:
la r3,theEvent(`bss)
lwz r4,Message(r3) ;window ptr
lwz r5,WindowPtr(`bss)
cmpw r4,r5
bne EventLoop ;not for us
lhz r4,Modify(r3) ;TE-2-20: EventRecord modifier flags
andi. r4,r4,activeFlag ;TE-2-21: check activate flag
beq Deactivate ;1 = activate
Activate:
lwz r3,WindowPtr(`bss)
Xcall SetPort ;I-2-42
lwz r3,VScrollHandle(`bss)
Xcall ShowControl ;TE-5-86
lwz r3,VScrollHandle(`bss)
Xcall GetControlMaximum ;TE-5-104
cmpwi r3,0
beq EventLoop ;need to hilite it if not zero
lwz r3,VScrollHandle(`bss)
li r4,0 ;TE-5-99: hiliteState: 0 = on, 255 = off
Xcall HiliteControl ;TE-5-98
b EventLoop
Deactivate:
lwz r3,VScrollHandle(`bss)
li r4,255 ;TE-5-99: hiliteState: 0 = on, 255 = off
Xcall HiliteControl ;TE-5-98
b EventLoop
OSEvent:
lwz r3,Message+theEvent(`bss) ;TE-2-80: suspend or resume events
andis. r4,r3,$0100 ;see if it’s suspend/resume
beq EventLoop ;exit if neither
andi. r3,r3,$0001 ;now check for suspend or resume
beq Deactivate ;it’s suspend
b Activate ;it’s resume
HighLevelEvent: ;we’re actually cheating here, but it works...
lwz r3,theEvent(`bss) ;EventRecord
lwz r4,Message(r3) ;TE-2-68, IC-4-58: event class
lis r5,"ae" ;load and shift into upper half
ori r5,r5,"vt" ;fill in the low half
cmpw r4,r5
bne EventLoop ;we don’t do 'FNDR' or 'sect' (Editions Manager) events
lwz r4,where(r3) ;TE-2-68, IC-4-58: event ID
lis r5,"oa"
ori r5,r5,"ap" ;open application
cmpw r4,r5
beq EventLoop ;looks to me like we’re already open
lis r5,"pd"
ori r5,r5,"oc" ;print document
cmpw r4,r5
beq EventLoop ;we don’t print ’em
lis r5,"qu"
ori r5,r5,"it" ;quit application
cmpw r4,r5
beq Quit ;this we can handle
lis r5,"od"
ori r5,r5,"oc" ;open document
cmpw r4,r5
b EventLoop ;we don’t do this one either
GetTheResources:
mflr r29
li r3,ROMMapHndl ;ROMMapHndl = $0B06
lwz r3,(r3) ;ROMMapHndl --> ROM map handle
lwz r13,(r3) ;ROM map handle --> ROM map ptr
lhz r14,24(r13) ;offset to type list
add r14,r13,r14 ;point at type list
lhz r20,(r14) ;get the indexed number of types
lhz r19,26(r13) ;offset to resource name list
add r19,r19,r13 ;ptr to resource name list
la r15,2(r14) ;point to first resource in type list
GTR1: lhz r16,4(r15) ;number of resources of this type
lhz r17,6(r15) ;offset to reference list
add r17,r17,r14 ;ptr to reference list for first resource
GTR2: la r18,String(`bss) ;will become one line in the window
lwz r3,(r15)
stw r3,(r18) ;resource type
addi r18,r18,3 ;it’s really 4, but we want to use the update form later
lhz r3,(r17) ;resource ID
bl NumberToString ;convert it to a string = theString(`bss)
la r3,theString(`bss)
li r4,8 ;want 8 chars, ID # right justified & padded with spaces
lbz r3,(r3)
sub r4,r4,r3 ;subtract out ID number length
li r5," "
GTR3: stbu r5,1(r18) ;put in a space
subic. r4,r4,1
bne GTR3
la r3,theString(`bss)
lbz r4,(r3) ;use the length byte as an index
GTR4: lbzu r5,1(r3)
stbu r5,1(r18)
subic. r4,r4,1
bne GTR4
lhz r3,2(r17) ;offset from beginning of resource name list to name
add r3,r3,r19 ;ptr to name in resource name list
lbz r4,(r3) ;get the string length byte
cmpwi r4,0 ;check string length
beq GTR7 ;don’t copy nothing
li r5," " ;a couple of spaces
sth r5,1(r18)
addi r18,r18,2
GTR5: lbzu r5,1(r3) ;get a byte of the resource name
stbu r5,1(r18)
subic. r4,r4,1 ;using the length byte as a loop counter
bne GTR5
GTR7: li r3,cr
stbu r3,1(r18)
addi r18,r18,1 ;we were pointing at the <cr>
la r3,String(`bss) ;ptr to the string
sub r4,r18,r3 ;subtract end from beginning = length
lwz r5,TEHandle(`bss)
Xcall TEInsert ;T-2-94
addi r17,r17,12 ;point to next entry in reference list
subic. r16,r16,1 ;decrement the resource index
bge GTR2 ;loop as long as we got some
addi r15,r15,8 ;point to next resource in type list
subic. r20,r20,1 ;decrement number of types counter
bge GTR1 ;loop ’til we run out of ’em
mtlr r29
blr
NumberToString: ;r3 = number to convert, must be -32768 thru 32767
la r4,theString(`bss) ;the destination
li r6,1 ;our index into the string (will become length byte)
cmpwi r3,32767 ;$7FFF
ble NTS0 ;anything larger is considered a negative number
li r5,"-"
stbx r5,r4,r6 ;stick the minus sign in there
addi r6,r6,1 ;increment the index
neg r3,r3 ;now the upper 16 bits are all 1s, so...
andi r3,r3,$FFFF ;...mask them off
; extsh r3,r3 ;this would work too because high bit is always 0
NTS0: cmpwi r3,10000 ;see if it’s 10000 or more
blt NTS2
li r5,-1 ;we’ll build our digit here
NTS1: subic. r3,r3,10000
addi r5,r5,1
bge NTS1 ;loop until it goes negative
ori r5,r5,$30 ;ASCII-ize the digit
stbx r5,r4,r6 ;put it in the string
addi r6,r6,1 ;bump up the index
addi r3,r3,10000 ;make it positive again
b NTS3
NTS2: cmpwi r3,1000 ;see if it’s 1000 or more
blt NTS5
NTS3: li r5,-1 ;digit building area
NTS4: subic. r3,r3,1000
addi r5,r5,1
bge NTS4
ori r5,r5,$30 ;ASCII-ize the digit
stbx r5,r4,r6
addi r6,r6,1
addi r3,r3,1000
b NTS6
NTS5: cmpwi r3,100 ;you get the idea from the previous ones
blt NTS8
NTS6: li r5,-1
NTS7: subic. r3,r3,100
addi r5,r5,1
bge NTS7
ori r5,r5,$30 ;ASCII-ize it
stbx r5,r4,r6
addi r6,r6,1
addi r3,r3,100
b NTS9
NTS8: cmpwi r3,10
blt NTS11
NTS9: li r5,-1
NTS10: subic. r3,r3,10
addi r5,r5,1
bge NTS10
ori r5,r5,$30
stbx r5,r4,r6
addi r6,r6,1
addi r3,r3,10
NTS11: ori r3,r3,$30
stbx r3,r4,r6
stb r6,(r4) ;put in the length byte
blr
CenterWindow:
mflr r29
Xcall GetMainDevice ;I-5-27
stw r3,GDHandle(`bss) ;save the main graphics device handle
lwz r4,(r3) ;GDHandle --> GDevice ptr (I-5-15)
lwz r3,WindowPtr(`bss) ;TE-4-69: WindowRecord --> I-2-31: GrafPort
lhz r5,gdRect+top(r4)
addi r5,r5,50 ;menu height + title bar + fudge factor
lhz r7,gdRect+right(r4) ;gdRect.right
lhz r6,portRect+right(r3) ;portRect.right
sub r4,r7,r6 ;gdRect.right - portRect.right = horizontal white space
li r6,1
srw r4,r4,r6 ;divide by 2 to get the distance from the left edge of the screen
lwz r3,WindowPtr(`bss) ;r4 = left, r5 = top of new window position
li r6,1 ;in front
Xcall MoveWindow ;TE-4-95
mtlr r29
blr
SizeDest:
lwz r3,WindowPtr(`bss)
la r3,portRect(r3) ;window’s portRect
lwz r4,TEHandle(`bss)
lwz r4,(r4) ;handle --> ptr to TERec
la r5,destRect(r4) ;destRect
lis r6,3 ;move top down 3 pixels
ori r6,r6,3 ;move left in 3 pixels
stw r6,topLeft(r5)
lhz r6,bottom(r3) ;get height of window
subi r6,r6,23 ;for scroll bar + border
lhz r7,lineHeight(r4) ;height of one line
divwu r6,r6,r7 ;how many lines fit in the window
mullw r6,r6,r7 ;back to height, drop remainder
addi r6,r6,3 ;for the 3 pixels at the top
sth r6,bottom(r5)
li r6,1000 ;make destRect.right = 1000 (way out in right field)
sth r6,right(r5)
blr
SizeView:
lwz r3,WindowPtr(`bss)
la r3,portRect(r3) ;window’s portRect
lwz r4,TEHandle(`bss)
lwz r4,(r4) ;handle --> ptr to TERec
la r5,viewRect(r4) ;viewRect
lis r6,3 ;move top down 3 pixels
ori r6,r6,3 ;move left in 3 pixels
stw r6,topLeft(r5)
lhz r6,bottom(r3) ;get height of window
subi r6,r6,20 ;for scroll bar
lhz r7,lineHeight(r4) ;height of one line
divwu r6,r6,r7 ;how many lines fit in the window
mullw r6,r6,r7 ;back to height, drop remainder
addi r6,r6,3 ;’cause we’re 3 down from the top
sth r6,bottom(r5)
lhz r6,right(r3)
subi r6,r6,23 ;in 20 pixels for scroll bar & 3 for the border
sth r6,right(r5)
blr
AdjustWindowSize:
mflr r29
lwz r3,WindowPtr(`bss)
la r3,portRect(r3) ;window’s portRect
lhz r4,right(r3)
lhz r5,left(r3)
sub r4,r4,r5 ;right - left = width
lwz r6,GDHandle(`bss) ;get the main graphics device handle
lwz r6,(r6) ;GDHandle --> GDevice ptr (I-5-15)
la r6,gdRect(r6) ;now have desktop rect
lhz r7,right(r6) ;desktop width
subi r7,r7,20 ;the fudge factor: 10 pixels left & right
cmpw r4,r7
ble AWS1 ;OK if smaller
mr r4,r7 ;use the window width if too big
AWS1: lhz r5,bottom(r6) ;screen height
subi r5,r5,65 ;a fudge factor to give us some foot room
lwz r3,WindowPtr(`bss) ;r4 = new width, r5 = new height
li r6,1 ;fUpdate = true
Xcall SizeWindow ;TE-4-101
mtlr r29
blr
SizeScrollBar:
mflr r27
lwz r6,WindowPtr(`bss)
la r13,portRect(r6) ;window’s portRect
lwz r3,VScrollHandle(`bss)
li r4,16 ;new width
lhz r5,bottom(r13) ;get portRect.bottom
subi r5,r5,13 ;grow box + fudge factor = new height
Xcall SizeControl ;TE-5-98
lwz r3,VScrollHandle(`bss)
lhz r4,right(r13) ;get portRect.right
subi r4,r4,15 ;grow box + fudge factor = left
li r5,-1 ;top
Xcall MoveControl ;TE-5-97
mtlr r27
blr
CalControl:
mflr r27
lwz r3,TEHandle(`bss)
lwz r7,(r3) ;TERec ptr
la r4,viewRect(r7)
lhz r5,bottom(r4) ;get height of window
lhz r6,lineHeight(r7) ;get the height of one line
divwu r4,r5,r6 ;how many lines fit in the window
lwz r3,VScrollHandle(`bss)
lhz r7,nLines(r7) ;number of lines of text
sub. r4,r7,r4 ;- (# lines in the window)
bge CC1
mr r4,r7 ;if few lines, set to max window will hold
CC1: Xcall SetControlMaximum ;TE-5-95
lwz r3,VScrollHandle(`bss)
li r4,0 ;new minimum value
Xcall SetControlMinimum ;TE-5-95
mtlr r27
blr
SaveTheResources:
mflr r29
bl NewResourceFile
li r3,ROMMapHndl ;ROMMapHndl = $0B06
lwz r3,(r3) ;ROMMapHndl --> ROM map handle
lwz r13,(r3) ;ROM map handle --> ROM map ptr
lhz r14,24(r13) ;offset to type list
add r14,r13,r14 ;point at type list
lhz r20,(r14) ;get the indexed number of types
lhz r19,26(r13) ;offset to resource name list
add r19,r19,r13 ;ptr to resource name list
la r15,2(r14) ;point to first resource in type list
li r18,RomMapInsert ;RomMapInsert = $0B9E, TmpResLoad = $0B9F
lwz r3,acurHandle(`bss)
lwz r3,(r3) ;acur handle --> acur record
lhz r23,(r3) ;get the number of cursors
subi r23,r23,1 ;indexing with a zero offset
la r21,CursorHandles(`bss) ;ptr to the array of cursor handles
li r22,0 ;start current cursor count at zero
STR1: lhz r16,4(r15) ;number of resources of this type
lhz r17,6(r15) ;offset to reference list
add r17,r17,r14 ;ptr to reference list for first resource
STR2: lwz r3,(r15) ;resource type
la r4,theType(`bss)
stw r3,(r4) ;stash the type
lhz r3,(r17) ;resource ID
la r4,theID(`bss)
sth r3,(r4) ;put in the ID
lhz r3,2(r17) ;offset from beginning of resource name list to name
add r3,r3,r19 ;ptr to name in resource name list
lbz r4,(r3) ;get the string length byte
la r5,RsrcName(`bss)
stb r4,(r5) ;put in the length byte
cmpwi r4,0 ;check string length
beq STR4 ;don’t try to copy it if there’s nothing there
STR3: lbzu r6,1(r3) ;copy the resource name
stbu r6,1(r5)
subic. r4,r4,1
bne STR3
STR4: li r3,MapTrue ;insert ROM map, load resource
sth r3,(r18)
lwz r3,theType(`bss)
lhz r4,theID(`bss)
Xcall GetResource ;MT-1-73
stw r3,RsrcHandle(`bss)
stw r3,NewRsrcHandle(`bss) ;old handle
la r3,NewRsrcHandle(`bss) ;VAR: new handle
Xcall HandToHand ;M-2-62
lwz r3,NewRsrcHandle(`bss)
Xcall HLock ;M-2-45
li r3,MapTrue ;insert ROM map, load resource
sth r3,(r18)
lwz r3,RsrcHandle(`bss)
Xcall DetachResource ;MT-1-108
lhz r3,ResFileNumber(`bss) ;need to do this BEFORE AddResource
Xcall UseResFile ;MT-1-69
lwz r3,NewRsrcHandle(`bss)
lwz r4,theType(`bss) ;rsrc type
lhz r5,theID(`bss) ;rsrc ID
la r6,RsrcName(`bss) ;rsrc name
Xcall AddResource ;MT-1-90
lhz r3,ResFileNumber(`bss) ;reference number
Xcall UpdateResFile ;MT-1-92
lwz r3,NewRsrcHandle(`bss)
Xcall HUnlock ;M-2-46
lwz r3,NewRsrcHandle(`bss)
Xcall HPurge ;M-2-47
lwz r3,NewRsrcHandle(`bss)
Xcall ReleaseResource ;MT-1-107
STR5: addi r17,r17,12 ;point to next entry in reference
subic. r16,r16,1 ;decrement the resource index
bge STR2 ;loop if there’re still some left
slwi r4,r22,2 ;multiply current cursor count by 4
lwzx r3,r21,r4 ;get an indexed handle
lwz r3,(r3) ;cursor handle --> cursor ptr
Xcall SetCursor ;I-8-25
addi r22,r22,1 ;up the index
cmpw r22,r23 ;see if we’ve gone through all of them
ble STR6
li r22,0 ;reset cursor count
STR6: addi r15,r15,8 ;point to next resource in type list
subic. r20,r20,1 ;decrement number of types counter
bge STR1 ;loop ’til there ain’t no more
Xcall InitCursor ;I-8-22
li r3,CurApRefNum ;back to ROM Sucker
Xcall UseResFile ;MT-1-69
lhz r3,ResFileNumber(`bss)
Xcall CloseResFile ;MT-1-110
mtlr r29
blr
NewResourceFile:
mflr r28
la r3,HParamBlkPtr(`bss) ;F-2-92: fileParam variant
li r4,0
stw r4,ioCompletion(r3) ;no completion routine
lwz r5,ResFileName(rtoc)
stw r5,ioNamePtr(r3)
sth r4,ioVRefNum(r3) ;volume number
stw r4,ioDirID(r3) ;directory ID number
Xcall PBHDeleteSync ;F-2-174
li r3,0 ;vRefNum
li r4,0 ;dirID
lwz r5,ResFileName(rtoc) ;resource file name
Xcall HCreateResFile ;MT-1-56
li r3,0 ;vRefNum
li r4,0 ;dirID
lwz r5,ResFileName(rtoc) ;resource file name
li r6,fsRdWrPerm ;MT-1-62: IO permission
Xcall HOpenResFile ;MT-1-62
sth r3,ResFileNumber(`bss) ;rsrc file refNum of the opened file
la r3,HParamBlkPtr(`bss) ;F-2-194: CInfoPBRec_File variant
li r4,0
stw r4,ioCompletion(r3) ;no completion routine
lwz r5,ResFileName(rtoc)
stw r5,ioNamePtr(r3)
sth r4,ioVRefNum(r3) ;volume number
sth r4,ioFDirIndex(r3) ;use ioNamePtr & ioVRefNum
stw r4,ioDirID(r3) ;directory ID number
Xcall PBHGetFInfoSync ;F-2-194
la r3,HParamBlkPtr(`bss) ;F-2-196: CInfoPBRec_File variant
li r4,0
stw r4,ioCompletion(r3) ;no completion routine
lis r5,"rs"
ori r5,r5,"rc" ;fdType = "rsrc"
stw r5,ioFlFndrInfo(r3)
lis r5,"RS"
ori r5,r5,"ED" ;fdCreator = "RSED"
stw r5,ioFlFndrInfo+4(r3)
stw r4,ioDirID(r3) ;directory ID number
Xcall PBHSetFInfoSync ;F-2-195
mtlr r28
blr
Quit:
tidy_up ;ends with a blr back to the Finder
*********************************************************
AboutText: data ;text to go in the About… box
DC.B "ROM Sucker",$0D,$0D
DC.B "A little hack to let you look at the resources in your ROM. Written "
DC.B "in 680x0 and PowerPC assembly language by",$0D,$0D
DC.B "Cliff Harris",$0D
DC.B "PO Box 4343",$0D
DC.B "Anaheim, CA 92803",$0D
DC.B "CliffH5@aol.com"
AboutTextEnd: data
align
ResFileName: data
PSTRING "•ROM Resources"
align
*********************************************************
* Low memory globals
CurApRefNum: EQU $0900 ;reference number of current application’s resource file
ROMMapHndl: EQU $0B06 ;handle to ROM resource map
RomMapInsert: EQU $0B9E ;set byte to $FF to put ROM in resource chain
TmpResLoad: EQU $0B9F ;set byte to $FF to load resources
* ASCII characters
cr: EQU $000D ;carriage return
* I-8-24: cursor types
iBeamCursor: EQU 1 ;text selection cursor
crossCursor: EQU 2 ;for drawing graphics
watchCursor: EQU 4 ;wristwatch to indicate a short operation in progress
* T-3-66: FontInfo record
ascent: EQU 0 ;ascent
descent: EQU 2 ;descent
leading: EQU 6 ;leading
* TE-5-89: control part codes
inButton: EQU 10
inCheckBox: EQU 11
inUpButton: EQU 20
inDownButton: EQU 21
inPageUp: EQU 22
inPageDown: EQU 23
inThumb: EQU 129
* TE-5-73: ControlRecord
contrlValue: EQU 18
* I-2-31: GrafPort
portBits: EQU 2 ;bitmap
portRect: EQU 16 ;grafPort’s rectangle
txFont: EQU 68 ;text font
txFace: EQU 70 ;text face
txMode: EQU 72 ;text mode
txSize: EQU 74 ;text size
* I-5-15: GDevice record
gdRect: EQU 34 ;GDevice rectangle
* I-2-29: Region
rgnBBox: EQU 2 ;region’s enclosing rectangle
* T-2-67: TERec
destRect: EQU 0
viewRect: EQU 8
lineHeight: EQU 24
fontAscent: EQU 26
hText: EQU 62 ;handle to the text
teFont: EQU 74
teSize: EQU 80
nLines: EQU 94
* constants for setting the RomMapInsert:TmpResLoad pair
MapTrue: EQU $FFFF ;link in ROM map and load resource
MapFalse: EQU $FF00 ;link in ROM map without loading a resource
* I-2-28: offsets for rectangles
top: EQU 0
left: EQU 2
bottom: EQU 4
right: EQU 6
topLeft: EQU 0
botRight: EQU 4
bottomRight: EQU 4
* T-4-15: font numbers
systemFont: EQU 0
chicago: EQU 0
geneva: EQU 3
monaco: EQU 4
* TE-2-79: EventRecord
What: EQU 0 ;TE-2-79: event type
Message: EQU 2 ;TE-2-80: event message
When: EQU 6 ;event time
where: EQU 10 ;TE-2-80: event ID for high-level events
thePt: EQU 10 ;global mouse posn: h,v
Modify: EQU 14 ;TE-2-80: modifiers
* TE-2-21: EventRecord modifier flags:
activeFlag: EQU 1 ;set if window is being activated
* TE-2-26: event mask
everyEvent: EQU -1 ;all events
* MousePt (local mouse coordinates)
MouseV: EQU 0 ;vertical coordinate
MouseH: EQU 2 ;horizontal coordinate
* TE-3-115: MenuResult (from MenuSelect)
menusID: EQU 0 ;menu ID
itemID: EQU 2 ;menu item ID
* T-2-89: text alignment (was "justification") used by TETextBox
teFlushDefault: EQU 0 ;whatever was already specified
teCenter: EQU 1 ;centered
teFlushRight: EQU -1 ;right aligned
teFlushLeft: EQU -2 ;left aligned
* T-2-73: transfer modes
srcOr: EQU 1
* F-2-91: HParamBlockRec
ioCompletion: EQU 12 ;ptr to completion routine
ioNamePtr: EQU 18 ;ptr to driver/file/directory name
ioVRefNum: EQU 22 ;volume specification
ioFDirIndex: EQU 28 ;set to zero to use ioNamePtr & ioVRefNum
ioFlFndrInfo: EQU 32 ;FInfo = file type and creator
ioDirID: EQU 48 ;directory or file ID
* MT-1-62: IO permissions
fsRdWrPerm: EQU 3 ;exclusive read/write permission
*********************************************************
DebugString: pstring ";ss e80;g"
align
* Use the debug string as follows:
* lwz r3,DebugString(rtoc)
* Xcall DebugStr
* stdx r0,r0,r0 ;••••••••••• it’s illegal!!!! •••••••••••••••
*********************************************************